package com.ytktt.study.week9.task3.rpcfx.filter;

import com.google.common.collect.Lists;
import com.ytktt.study.week9.task3.rpcfx.api.RpcfxRequest;
import lombok.RequiredArgsConstructor;

import java.util.List;

/**
 * 过滤器链
 *
 * @author ytk
 */
@RequiredArgsConstructor
public class RequestFilterChain {

    private final List<RequestFilter> filterList;

    public boolean filter(RpcfxRequest request) {
        for (RequestFilter filter : this.filterList) {
            boolean result = filter.filter(request);
            if (!result) {
                return false;
            }
        }
        return true;
    }

    public void addFilter(RequestFilter filter) {
        this.filterList.add(filter);
    }
}
